package com.example.demo.day.config.learn.design.responsibity.x1;

public abstract class Leader {
    private Leader mNextHandler;

    public Leader(Leader nextHandler) {
        mNextHandler = nextHandler;
    }

    //如果自己能处理该金额，则自己处理,否则需分发给下一级领导进行处理
    //处理成功时，返回true，否则返回false
    public final boolean dispatchRequest(int money) {
        if (money <= getLimit()) {
            return handleRequest(money);
        }
        if (mNextHandler != null) {
            return mNextHandler.dispatchRequest(money);
        }
        return false;
    }

    public abstract int getLimit();
    public abstract boolean handleRequest(int money);
}
